Format Time with Javascript

Use Javascript's built in functions to format time. You could even dynamically show time depending on locale / region of the User.

This could remove the need for #3rd-party libraries like date-fnsor Moment.js

const timeString = '12:00:00'

const timeString12hr = new Date('2024-01-01T' + timeString + 'Z')
  .toLocaleTimeString(
	  'en-US',
	{
	    timeZone:'UTC',
	    hour12:true,
	    hour:'numeric',
	    minute:'numeric'
	}
  );

Credits